package com.example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.service.UserService;
import com.example.repository.UserRepository;

@Service("userService") // 使用@Service注解标识这是一个服务层组件
public class UserServiceImpl implements UserService {
    
    // 使用@Autowired自动注入依赖
    @Autowired
    private UserRepository userRepository;
    
    @Override
    public void addUser(String username) {
        System.out.println("服务层：添加用户 - " + username);
        userRepository.saveUser(username);
    }
    
    @Override
    public String getUserInfo() {
        return "当前用户信息: " + userRepository.getLatestUser();
    }
    
    @Override
    public int getUserCount() {
        return userRepository.getUserCount();
    }
}